home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 753 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.9 KB

  1. Path: teal.csn.net!not-for-mail
  2. From: thads@csn.net (Thad Smith)
  3. Newsgroups: comp.std.c
  4. Subject: Re: valueless return statement in non-void function
  5. Date: 16 Apr 1996 21:41:21 -0600
  6. Organization: T3 Systems
  7. Message-ID: </REdxQ9ytt2Y089yn@csn.net>
  8. References: <829573502snz@wbriscoe.demon.co.uk>
  9. Reply-To: ThadSmith@acm.org
  10. NNTP-Posting-Host: 199.117.27.22
  11.  
  12. In article <829573502snz@wbriscoe.demon.co.uk>,
  13. walter briscoe <walter@wbriscoe.demon.co.uk> wrote:
  14. >I recently had trouble moving some K&R code to ISO C.
  15. >
  16. >Specifically, a function without a return statement was used to return a
  17. >value with an implicit return at the } terminating the function.
  18. >
  19. >Section 6.6.6.4 of ANSI/ISO 9899-1990 contains the Semantic restriction
  20. >> If a return statement without an expression is executed, and the value
  21. >> of the function call is used by the caller, the behavior is undefined.
  22. >
  23. >It goes on to say:
  24. >> Reaching the } that terminates the function is equivalent to executing
  25. >> a return statement without an expression.
  26. >
  27. >I am surprised/irritated that the undefined behavior is in the caller
  28. >rather than the called function.
  29.  
  30. It must be so for compatibility with K&R, as you note.
  31.  
  32. >The obvious objection to such a statement is that it conflicts with
  33. >prior art.  I would answer that by making the implicit type of
  34. >declarations void rather than int.  That would allow less unreasonable
  35. >prior art to port without complaint.  
  36.  
  37. I haven't worked with much K&R code, so don't know how valid that is.
  38. I suspect that there is lots of legacy code with an implicit int
  39. return type that actually returns values.  My early impression of C
  40. was that much code was designed to be parsimonious.
  41.  
  42. The following proposal would be somewhat better: if the return type is
  43. explicitly typed, the return statement must provide a value.
  44. Someone will surely trot out some existing working code that violates
  45. this, however.
  46.  
  47. In the meantime, use a good lint.
  48.  
  49. Thad
  50.